import Vue from 'vue'
import App from './App'
import api from './common/api.js'
import urlConfig from './common/config.js'
import utils from './common/utils.js'
Vue.prototype.$utils = utils
Vue.prototype.$http = api
Vue.prototype.$urlConfig = urlConfig
Vue.config.productionTip = false
App.mpType = 'app'



//用户是否登录 未登录跳转到登录页面,登录后判断session_key(==token)是否失效，失效重新wxlogin()
const token = wx.getStorageSync('token'); //获取来自主页弹框登录的token
console.log('token:' + token);

// 封装的路由守卫
// import uniCrazyRouter from './components/crazy-router/index.js';
// Vue.use(uniCrazyRouter)
// uniCrazyRouter.beforeEach(async (to, from ,next)=>{
// 	const isLogin = uni.getStorageSync("accessToken") ? true : false;
// 	// 如果有token，或在其他不需要token的页面
// 	if (isLogin || to.url == 'pages/login/login' || to.url == 'pages/resister/resister' || to.url == 'pages/forget/forget') {
// 		next();
// 	}else{
// 		uniCrazyRouter.afterNotNext(() => {
// 			uni.navigateTo({url: '/pages/login/login'});
// 		})
// 	}
// })

// 注册全局popup组件
// import uniPopup from './components/uni-popup/uni-popup.vue'
// Vue.component('uni-popup',uniPopup)

//封装的请求
// import Request from './components/luch-request/index.js' 
// const http = new Request();
// const token = uni.getStorageSync('accessToken') || '';
// http.setConfig((config) => { /* 设置全局配置 */
//   config.baseUrl = 'https://api.lovepingou.com'
//   config.header = {
//     ...config.header,
//     token: token,
// 		'content-type': 'application/x-www-form-urlencoded'
//   }
//   return config
// })
// http.interceptor.response((response) => { /* 请求之后拦截器 */
//   if (response.data.code === 998 || response.data.code === 999 || response.data.code === 996) { // 998登陆过期,996账户冻结
// 		console.log(response.data);
// 		uni.clearStorage();
// 		uni.clearStorageSync();
// 		uni.showToast({title: response.data.msg, icon: 'none'});
// 		uni.navigateTo({url: '/pages/login/login'});
//   }
//   return response
// }, (response) => { // 请求错误做点什么
//   return response
// })
// Vue.prototype.$http = http;

// 封装的url跳转
Vue.prototype.Router = function (url, type) {
	if(type == 'reLaunch') {
		uni.reLaunch({url: url});
	}else if(type == 'back'){
		uni.navigateBack();
	}else{
		uni.navigateTo({url: url});
	}
}

const app = new Vue({
	...App
})
app.$mount()
